package oop2;

/**
 * @author oldliu
 * @since 1.0
 */
public class Banji {
    String name;
    String dirName;
    //学生信息,最多30人
    String[] stus = new String[30];
    //int count=0;//当前人数
    //加新生
    public void addNewStu(String newName) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null) {
                stus[i] = newName;
                return;//!!!
            }
        }
        System.out.println("人已满，坐不下了");
    }

    //班级信息
    public void showClsInfo() {
        System.out.println("班级名称：" + name + ",指导老师:" + dirName);
        System.out.println("学生名单如下：");
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] == null)
                break;
            System.out.print(stus[i] + " ");
        }
        System.out.println();
    }

    //找人！
    public boolean search(String stuName) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i].equals(stuName)) {
                return true;
            }
        }
        return false;
    }

    //限制查找范围,起点和终点
    public boolean search2(int start, int end, String stuName) {
        for (int i = start; i >= 0 && i < stus.length && i <= end; i++) {
            if (stus[i] != null && stus[i].equals(stuName)) {
                return true;
            }
        }
        return false;
    }
//    public void search(String stuName){
//        for (int i = 0; i < stus.length; i++) {
//            if(stus[i]!=null&& stus[i].equals(stuName)){
//                System.out.println(stuName+"在这个班");
//                return;
//            }
//        }
//        System.out.println(stuName+"不在这个班");
//    }
    //改名字！!!
    public boolean modify(String oldName,String newName){
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null && stus[i].equals(oldName)) {
                stus[i]=newName;
                return true;
            }
        }
        return false;
    }
}
